package modelLayer;

 


/**
 * Write a description of class StaffContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

import java.util.ArrayList;

public class StaffContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Staff> staff;
    private static StaffContainer instance;

    /**
     * Constructor for objects of class StaffContainer
     */
    public StaffContainer()
    {
        // initialise instance variables
        staff = new ArrayList<>();
    }

    public static StaffContainer getInstance(){
        if (instance == null) {
            instance = new StaffContainer();
        }
        return instance;
    }
    
    public void addStaff (Staff newStaff) {staff.add(newStaff);}
    public boolean removeStaff (Staff newStaff) {return staff.remove(newStaff);}
    public ArrayList<Staff> getAllStaff() {return staff;}
    public Staff getStaff(String username) {
     int i;
     Staff s=null;
     for (i=0; i<staff.size(); i++) {
        if (username.equals(staff.get(i).getUsername())) {
            s=staff.get(i);
        }
        }
        return s;
    }
    
    public void printStaffInfo(String username) {
        int i;
        boolean found=false;
        for (i=0; i<staff.size(); i++) {
            if (username.equals(staff.get(i).getUsername())) {
             System.out.println("Name: " + staff.get(i).getName() +"\n"+"Phone number: " +
             staff.get(i).getPhoneNo() +"\n"+ "CPR number: " + staff.get(i).getCprNo()+"\n"+"Username: " +
             staff.get(i).getUsername()+"\n" + "Password: *****"); 
             if (staff.get(i).getIsManager()==true){
                 System.out.print("Position: manager" + "\n");
                }
                else {
                    System.out.print("Position: employee" + "\n");
                }
                found =true;
            }
       } 
       if (found==false) {
          System.out.println("User does not exist!");
        }
    }
    
    public void printAllStaffInfo() {
        int i;
        boolean found=false;
        
        for (Staff s: staff) {
            System.out.println("Name: " + s.getName() +"\n"+"Phone number: " +
             s.getPhoneNo() +"\n"+ "CPR number: " + s.getCprNo()+"\n"+"Username: " +
             s.getUsername()+"\n" + "Password: *****"); 
             if (s.getIsManager()==true){
                 System.out.print("Position: manager"+"\n");
                }
                else {
                    System.out.print("Position: employee"+"\n");
                }
                System.out.println("///////////////////////");
                found =true;
        }
    }
    
    public void updateStaff(Staff staff, String name, String phoneNo, int cprNo, String username, String password, boolean isManager){      
                staff.setName(name);
                staff.setPhoneNo(phoneNo);
                staff.setCprNo(cprNo);
                staff.setUsername(username);
                staff.setPassword(password);
                staff.setIsManager(isManager);   
    }
}
